<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体检登记</title>
</head>
<body>
<script type="text/javascript">
   $(function(){
	   //体检项目
	   $('#checkpackage-tab').datagrid({
		    url:'init-healproject',
 		    columns:[[
 		    	   {field:'prolid',title:'',width:40,checkbox:true},
 		    	   {field:'project_no',title:'编号',width:150},
 		    	   {field:'project_name',title:'项目名称',width:170},
 				   {field:'project_price',title:'项目价格',width:150}
 		    ]]
		});
	   
	   //体检预约（新增医疗卡,新增体检预约表和开立体检项目）或者套餐
	   $("#add-health-oppoint").click(function(){
		   $("#addoppoint").form({
				url:'add-healthoppoint2',
				onSubmit:function(param){
			        var c=$('#addoppoint').form("validate");
		     		if(!$('#addoppoint').form('validate')){//调用validate方法校验
	                    $.messager.show({
	                        title:'提示信息' , 
	                        msg:'验证没有通过,不能提交表单!'
	                    });
                    return false ;        //当表单验证不通过的时候 必须要return false 
             		} 
					
					var tab=$('.ttabs').tabs('getSelected');
        		    var title=tab.panel('options').title;
					//获取表格中的发药的记录
					var prows = $('#checkpackage-tab').datagrid('getChecked');
					var mrows = $('#checkexaminations-tab').datagrid('getChecked');
					if(prows.length==0 && mrows.length==0){
						$.messager.confirm('Confirm', 
    							'项目不能为空，请选择'+title+'或者', 
    							function(r){
    					});
						return false;
					}
					if(prows.length!=0 && mrows.length!=0){
						$.messager.confirm('Confirm', 
    							'单个项目和套餐不能同时开', 
    							function(r){
    					});
						return false;
					}
					if(prows.length==0){
						$.messager.confirm('Confirm', 
    							'选择的是：'+title, 
    							function(r){
    					});
						for(var  j = 0;j< mrows.length; j++){
							param["meal["+j+"].mealNo"] = mrows[j]["meal_no"];
							param["appoint.appoPeople"] =$("#pel").val();
							param["appoint.appoStatus"] =0;
					
						}
					}
					if(mrows.length==0){
						$.messager.show({
							title:'My Title',
							msg:'选择的是：'+title,
							timeout:3000,
							showType:'slide'
						});
						for(var  i = 0;i < prows.length; i++){
							param["project["+i+"].projectNo"] = prows[i]["project_no"];
							param["appoint.appoPeople"] =$("#pel").val();
							param["appoint.appoStatus"] =0;
					     }
					}
	
				},
				success:function(date){
					 $.messager.show({
	                        title:'提示信息' , 
	                        msg:'预约成功，请去门诊收费处进行交钱！'
	                 });
			    	$('#checkpackage-tab').datagrid('clearChecked');
				    $('#checkexaminations-tab').datagrid('clearChecked');
				    $("#addoppoint").form('clear');
				}
		   }).submit();
  
	   });
	   
	   //体检套餐
	   $('#checkexaminations-tab').datagrid({
		    url:'init-mealprojectall',
		    columns:[[
		    	   {field:'ciid',title:'',width:100,checkbox:true},
		    	    {field:'meal_no',title:'编号',width:100},
		    	 	{field:'meal_name',title:'套餐名称',width:130},
					{field:'meal_price',title:'套餐价格',width:100},
					{field:'ops',title:'操作',width:140,
						formatter:function(value,row,index){
							var btn ='<a id="ops-btn" class="editcls" onclick="lookexaminationdetails(\''+row.meal_no+'\')" href="javascript:void(0)">查看体检项目</a>';
							 return btn;
						}	
					}
		    ]],
			onLoadSuccess:function(data){
				console.log(data);
		        $('.editcls').linkbutton({
		        	text:'查看体检项目',
		        	plain:true,
		        	iconCls:'icon-edit'
		        }); 
		    }  
		});
	  
		
	   //取消按钮
	   $("#colse-health").click(function(){
		   $("#addoppoint").form('clear');
	   });
	   
	 //初始化科室下拉表的数据
		$('#sectionsh').combobox({   
        	url:'init-hospsection',//数据源
        	valueField: 'section_id',//实体类名字---主键id
	        textField: 'section_name',//需要显示在下拉框的实际内容
	        editable:false,
           panelHeight:'auto',//高度根据内容自动定
           onHidePanel: function(){
           	//床位号的下拉列表
			     $("#hospuserdoch").combobox("setValue",'');
			     var sid = $('#sectionsh').combobox('getValue'); 
				 $.ajax({
				 type: "Post",
				 url: "init-hospuserdoctor?sid="+sid,
				 cache: false,
				 dataType : "json",
				 success: function(data){
					 $("#hospuserdoch").combobox("loadData",data);
					 }
				 }); 
			  }

       });
		
		
		//医生的初始化数据
		$('#hospuserdoch').combobox({   
        	//url:'init-hospuserdoctor',//数据源
        	valueField: 'user_id',//实体类名字---主键id
	        textField: 'user_name',//需要显示在下拉框的实际内容
	        editable:false,
           panelHeight:'auto',//高度根据内容自动定
           onLoadSuccess: function () {  //加载完成后,设置选中第一项
                   var val = $(this).combobox("getData");
                   for (var item in val[0]) {
                       if (item == "user_id") {
                       	//初始化数据默认选中第一个
                           $(this).combobox("select", val[0][item]);
                       }
                   }
            }

           });
   });

   //套餐详情
   function lookexaminationdetails(meal_no){
	   //体检套餐详情
	   $('#lookcheckdetails-tab').datagrid({
		    url:'find-mealprojectbyid',
		    queryParams:{
		    	mno:meal_no
		    },
  		    columns:[[
  		    	   {field:'project_no',title:'编号',width:160},
  		    	   {field:'project_name',title:'项目名称',width:160},
  				   {field:'project_price',title:'项目价格',width:160}
  		    ]]
		});
	   $("#lookexamination-detailswin").window('open');
   }
   
	//验证
	$.extend($.fn.textbox.defaults.rules, {
		//姓名验证
		txtName: {
	        validator: function(value, param) {
	            var reg = /^[\u4e00-\u9fa5]+$/i;
	            return reg.test(value);
	        },
	        message: "姓名请输入中文"
	    },
	    //身份证号验证
	    cradsumAge:{
	        validator: function(value, param) {
				var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				if(reg.test(value)==true){
					 //获取身份证的的name的名字
					var inputValueName = $(this).next("input").attr("name");
					if(inputValueName == "clinic.clinicIdnumber"){
						inform_crad = this.value;//获取身份证
					}
				    //截取年计算年龄
				    var c_year=inform_crad.substring(6,10);
				    //获取系统的年份
				    var curr_time=new Date();   
					var curr_year=curr_time.getFullYear();
					//计算
				    var clinics_age = curr_year - c_year;
					//赋值给年龄
				    $('#inform-age').textbox('setValue',clinics_age);
				    //截取倒数第二个数，如果为1，性别为男，如果为2，性别为女
				    var crad_sex=inform_crad.substring(16,17);
				    if(crad_sex==1){
				    	//赋值给性别
					    $("#inform-sex").textbox('setValue',"男");
				    }else if(crad_sex==2){
				    	$("#inform-sex").textbox('setValue',"女");
				    }
				    
				    return reg.test(value);
				}
	         
	        },
	        message: "请输入正确的身份证号"
	    },
	    //手机号码验证
	    phone:{
	    	validator:function(value,param){
	    		 var regTel=/(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
	    		 return regTel.test(value);
	    	},
	    	message:"请输入正确的手机号"
	    }
   });//自定义验证
</script>

 <div class="checkup-examinationbox">
        <fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:420px;margin-left:30px;margin-top:20px;height:450px;float:left;">
             <legend>登记病人信息</legend>
             <form id="addoppoint" method="Post">
             <p>
						<a style="margin-left: 15px;">
		                   <span style="margin-right:7px;">医疗卡号</span>
					       <input id="inform_medicalcrad" name="clinic.cliniccardId" class="easyui-textbox" value="${clinicid }" data-options="width:120,height:30,required:true">
		                </a>
			    		<a style="margin-left: 25px;">
		                   	<span style="margin-right:7px;">病人姓名</span>
							<input id="sickuname" name="clinic.clinicName" class="easyui-textbox"  data-options="width:120,height:30,required:true,validType:['txtName']">
	                   </a>
					</p>
					<p style="margin-top: 40px;">
					 <a style="margin-left: 15px;">
	                	<span style="margin-right:7px;">身份证号</span>
	                	<input id="identity" name="clinic.clinicIdnumber" class="easyui-textbox"  data-options="validType:['cradsumAge'],width:320,height:30,required:true"></input>
	               		<span>
	               		    <input  type="hidden" name="" class="textbox-value"  value></input>
	               		</span>
		              </a>	
					</p>
					<p style="margin-top: 40px;">
					  <a style="margin-left: 15px;">
					    <span style="margin-right:25px;">年龄</span>
	                    <input id="inform-age" name="clinic.clinicAge" class="easyui-textbox" type="text" style="width:120px; height: 30px;line-height: 28px;border-radius: 5px;"></input>
					   </a>
                       
					   <a style="margin-left: 25px;">
						<span style="margin-right:25px;">性别</span>
						<input id="inform-sex" name="clinic.clinicSex" class="easyui-textbox" type="text" style="width:120px; height: 30px;line-height: 28px;border-radius: 5px;"></input>
						
					   </a>
						
					</p>
					<p style="margin-top: 40px;">
					    <a style="margin-left: 15px;">
						    <span style="margin-right:25px;">科室</span>
						    <select id="sectionsh" class="easyui-combobox" data-options="width:120,height:30,required:true" name="clinic.sectionId">
							</select>	
						</a>
					   <a style="margin-left: 25px;">
		                	<span style="margin-right:7px;">体检医生</span>
		                	<select id="hospuserdoch" name="hospdoctorname" class="easyui-combobox" data-options="width:120,height:30,required:true"  >
							</select>
			            </a>
			            
						
					</p>
					<p style="margin-top:40px;">
					  <a style="margin-left: 15px;">
		                  <span style="margin-right:7px;">联系电话</span>
		                  <input id="tel"  name="clinic.clinicTel" class="easyui-textbox"  data-options="width:120,height:30,required:true,validType:['phone']"/>
		              </a>
					  <a style="margin-left:25px;">
							<span style="margin-right:18px;">经办人</span>
							<input id="pel" value="${user.userName}" name="clinic.clinicHandlename" class="easyui-textbox"  data-options="width:120,height:30,required:true">
						</a>
						
					</p>
					<p style="margin-top:40px;">
					   <a style="width:100px;margin-left: 30px;height:30px;border-radius:6px;" id="add-health-oppoint" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
						<a style="width:100px;margin-left: 50px;height:30px;border-radius:6px;" id="colse-health" class="easyui-linkbutton" iconCls="icon-no">清空</a>
					</p>
             </form>
         </fieldset>    
         
         <fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:600px;height:450px;margin-left:20px;margin-top:20px;float:left;">
             <legend>体检项目信息</legend>
	         <div id="checkupall-plane" class="ttabs easyui-tabs" style="width:550px;height:400px;">
				    <div title="体检项目" style="padding:20px;display:none;">
				    	  <table id="checkpackage-tab" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false,width:500">
					       </table>
	     			</div> 
	     		    <div title="体检套餐" style="padding:20px;display:none;">
				    	  <table id="checkexaminations-tab" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false,width:500,height:320">
					      </table>
	     			</div> 
	 	      </div>
         </fieldset>
</div>   

<!-- 查看套餐详情 -->
<div id="lookexamination-detailswin" class="easyui-window" title="体检项目" style="width:500px;height:400px"
		    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
    <table id="lookcheckdetails-tab" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:false,width:485" >
	</table>
</div>
  
  
  <!-- 弹框提示 -->
    <div id="warminghealth-win" class="easyui-window"  title="提示框" style="width:300px;height:156px"
    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
          <p class="window-health" style=" margin-left: 72px;font-size: 16px;margin-top: 47px;">
          </p>
    </div>    
</body>
</html>